import Cookies from 'js-cookie'

export function useToken() {
  const TOKEN_KEY = 'sys-token'

  const getToken = () => Cookies.get(TOKEN_KEY)

  const setToken = (token: string) => {
    // firefox 和 safari 都不支持 cookieStore
    Cookies.set(TOKEN_KEY, token, { path: '/' })
  }

  const deleteToken = () => {
    Cookies.remove(TOKEN_KEY, { path: '/' })
  }

  return {
    getToken,
    setToken,
    deleteToken,
  }
}
